import 'virtual:windi.css';
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
import initPlugins from '@/plugins';
import microApp from '@micro-zoe/micro-app';

const app = createApp(App);

initPlugins(app);

app.use(store);
app.use(router);
app.mount('#app');

microApp.start({
  plugins: {
    modules: {
      'appname-vite': [
        {
          loader(code) {
            if (process.env.NODE_ENV === 'development') {
              // 这里 basename 需要和子应用vite.config.js中base的配置保持一致
              code = code.replace(/(from|import)(\s*['"])(\/vite-demo\/)/g, all => {
                return all.replace('/vite-demo/', 'http://localhost:5002/vite-demo/');
              });
            }
            return code;
          },
        },
      ],
    },
  },
  lifeCycles: {
    created(e) {
      console.log('基座 lifeCycles >>> created');
    },
    beforemount(e) {
      console.log('基座 lifeCycles >>> beforemount');
    },
    mounted(e) {
      console.log('基座 lifeCycles >>> mounted');
    },
    unmount(e) {
      console.log('基座 lifeCycles >>> unmount');
    },
    error(e) {
      console.log('基座 lifeCycles >>> error');
    },
  },
});
